<template>
  <i-frame :src="url" />
</template>
<script>
import iFrame from "@/components/iFrame/index";
export default {
  name: "onlinepreview",
  components: { iFrame },
  data() {
    return {
      url: ""
    };
  },
  created() {
    debugger
    // 获取域名
    var hostname = window.location.hostname;
    // var currentURL = window.location.href;
    var action = this.$route.query.url;// 要预览文件的访问地址
    if (!/^(http|https):\/\//.test(action)) {
      action ="http://" + hostname + process.env.VUE_APP_BASE_API + action
    }
    var extension = action.split('.').pop().toLowerCase();
    // 对 URL 进行 Base64 编码
    // http://localhost/dev-api/profile/upload/2024/04/10/%E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_20240410142436_20240410170914A003.jpg
    var encodedUrl = window.btoa(unescape(encodeURIComponent(action)));
    if (extension === 'pdf' || extension === 'doc' || extension === 'docx') {
      encodedUrl = encodedUrl + "&officePreviewType=pdf"
    }
    // this.url = "http://bt.shuangluoshu.cn/onlinePreview?url=aHR0cDovL3FuLnNodWFuZ2x1b3NodS5jbi8lRTUlQUUlOUQlRTQlQkYlQTElRTklODAlOUElRTglQUYlOUQlRTglQUUlQjAlRTUlQkQlOTUlRTklODclOEQlRTUlQTQlOEQlRTYlOEYlOTIlRTUlODUlQTUlRTYlOTUlODUlRTklOUElOUMlRTUlODglODYlRTYlOUUlOTAuZG9jeA==&officePreviewType=pdf";
    this.url = process.env.VUE_APP_ONLINE_PREVIEW + encodedUrl
    console.log("地址："+process.env.VUE_APP_ONLINE_PREVIEW+encodedUrl)
  }
}

</script>